package com.zzgc.modules.service.impl;

import com.zzgc.common.dao.AuthRoleRightDao;
import com.zzgc.common.entity.AuthRoleRight;
import com.zzgc.modules.service.AuthRoleRightService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 角色菜单关系表(AuthRoleRight)表服务实现类
 *
 * @author makejava
 * @since 2022-12-19 17:25:31
 */
@Service("authRoleRightService")
public class AuthRoleRightServiceImpl implements AuthRoleRightService {
    @Resource
    private AuthRoleRightDao authRoleRightDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AuthRoleRight queryById(Long id) {
        return this.authRoleRightDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param authRoleRight 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AuthRoleRight> queryByPage(AuthRoleRight authRoleRight, PageRequest pageRequest) {
        long total = this.authRoleRightDao.count(authRoleRight);
        return new PageImpl<>(this.authRoleRightDao.queryAllByLimit(authRoleRight, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param authRoleRight 实例对象
     * @return 实例对象
     */
    @Override
    public AuthRoleRight insert(AuthRoleRight authRoleRight) {
        this.authRoleRightDao.insert(authRoleRight);
        return authRoleRight;
    }

    /**
     * 修改数据
     *
     * @param authRoleRight 实例对象
     * @return 实例对象
     */
    @Override
    public AuthRoleRight update(AuthRoleRight authRoleRight) {
        this.authRoleRightDao.update(authRoleRight);
        return this.queryById(authRoleRight.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.authRoleRightDao.deleteById(id) > 0;
    }
}
